package com.jxb.lession76.web.servlet;

import com.jxb.lession76.common.Constant;
import com.jxb.lession76.entity.Emp;
import com.jxb.lession76.services.EmpServices;
import com.jxb.lession76.services.impl.EmpServicesImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/login")
public class LoginController extends BaseController {
    private EmpServices es = new EmpServicesImpl();

    public String doLogin(HttpServletRequest req, HttpServletResponse resp){
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        Emp emp = es.getEmpByUsername(username,password);
        if (emp != null && password.equals(emp.getPwd())) {
            req.getSession().setAttribute("emp",emp);
            return Constant.Re.FORWARD + "/index.jsp";
        }
        return Constant.Re.REDIRECT + "login.jsp";
    }
}
